package me.miencraft.plugin.superlobby.command;

import me.miencraft.plugin.superlobby.SuperLobby;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class MainCommand implements TabExecutor {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (args.length == 0) {
            sender.sendMessage("§eSuperLobby v1.0.0");
            return false;
        }
        String cmd = args[0].toLowerCase();
        if (cmd.equals("reload")) {
            sender.sendMessage("配置重载成功！");
            SuperLobby.mainConfig.load();
            SuperLobby.spawnConfig.load();
        } else if (cmd.equals("setspawn")) {
            if (!(sender instanceof Player)) return false;
            Player player = (Player) sender;
            SuperLobby.spawnConfig.setLocation(player.getLocation());
            sender.sendMessage("已设置出生点！");
        }
        return true;
    }

    @Nullable
    @Override
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
        return Arrays.asList("reload", "setspawn");
    }

}
